#ifndef ALIEN_ATTCK_VECTOR2D_H
#define ALIEN_ATTCK_VECTOR2D_H

#include <iostream>
#include <cmath>

struct Vector2D
{
    float m_x;
    float m_y;

    Vector2D()
    {
        m_x = 0;
        m_y = 0;
    }

    Vector2D(float x, float y) : m_x(x), m_y(y) {}

    const float getX() { return m_x; }
    const float getY() { return m_y; }

    void setX(float x) { m_x = x; }
    void setY(float y) { m_y = y; }
    // (x^2 + y^2) ^ 0.5
    int length() { return sqrt(m_x * m_x + m_y * m_y); }

    Vector2D operator+(const Vector2D &rhs) const
    {
        return Vector2D(m_x + rhs.m_x, m_y + rhs.m_y);
    }

    friend Vector2D &operator+=(Vector2D &lhs, const Vector2D &rhs)
    {
        lhs.m_x += rhs.m_x;
        lhs.m_y += rhs.m_y;

        return lhs;
    }

    Vector2D &operator*(float scalar)
    {
        return Vector2D(m_x * scalar, m_y * scalar);
    }

    Vector2D &operator*=(float scalar)
    {
        m_x *= scalar;
        m_y *= scalar;

        return *this;
    }

    Vector2D &operator/(float scalar)
    {
        return Vector2D(m_x / scalar, m_y / scalar);
    }

    Vector2D &operator/=(float scalar)
    {
        m_x /= scalar;
        m_y /= scalar;
        return *this;
    }

    void normalize()
    {
        int len = length();
        if (len > 0)
        {
            (*this) *= 1 / len;
        }
    }
};

#endif // header file protect